package huixue.cn.com.rxapp.ui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;

import java.util.ArrayList;
import java.util.List;

import huixue.cn.com.rxapp.R;
import huixue.cn.com.rxapp.adapter.MyItemTouchHelperCallback;
import huixue.cn.com.rxapp.adapter.RecycleViewAdapter;

public class RecycleViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle_view);

        final List<String> datas = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            datas.add(String.valueOf(i));
        }

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);

        //1.设置适配器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        RecycleViewAdapter adapter = new RecycleViewAdapter(this, datas);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);

        //2.设置ItemTouchHelper
        ItemTouchHelper.Callback callback = new MyItemTouchHelperCallback(adapter);
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
        itemTouchHelper.attachToRecyclerView(recyclerView);
    }
}
